<!doctype html>
<html>
<head>
    <include file="Public/head"/>
    <link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
    <link href="__CSS__/index.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="__JS__/jquery.js"></script>
    <script type="text/javascript" src="__JS__/jquery.inputbox.js"></script>
    <script type="text/javascript">
        $(function(){

            $('div[name="city"]').inputbox({
                height:24,
                width:100
            });
//
//            $('.cbt').inputbox();
//
//            $('[name="rbt"], [name="rbt2"]').inputbox();

        });
    </script>
</head>
<body style="background:#eee;">
<header id="header">
    <div class="header_l"> <a class="ico_10" href="javascript:history.go(-1);"> 返回 </a> </div>
    <h1 style="line-height: 50px;">收货地址</h1>
    <!--<div class="header_r"><a class="edit" href="{:U('Cart/edit')}" style="text-indent:0;line-height: 50px;font-size: 16px;">编辑</a></div>-->
</header>
<volist name="list" id="address">
    <div class="administration">
        <div class="address-name">{$address.name}<span class="fr">{$address.mobile}</span></div>
        <p>{$address.address}</p>
        <div class="default">
            <!--<div data-id="{$address.id}" data-i="{$i}" class="cbt margin-top cb <eq name="address.default" value="1">cb_active</eq>" name="check" type="checkbox" val="1">-->
                <!--<input type="checkbox" hidden="hidden" name="default" value="{$address.id}">-->
            <!--</div>默认地址-->
            <!--<div class="cbt a-margin " name="check" type="checkbox" val="5" ></div>-->
            <a href="{:U('Address/delete',array('id'=>$address['id']))}" style="float:right"><span class="shanchu">删除</span></a>
            <a href="{:U('Address/edit',array('id'=>$address['id'],'url'=>(urlencode("__SELF__"))))}" class="margin-l mr" style="float:right;"><span class="bianji">编辑</span></a>
            
        </div>
    </div>
</volist>
<script>
    check($(".cbt"));
    function check(that){
        console.log(that);
        for(var i=0; i<that.length; i++){
            var input = $(that[i]).children("input");
            if($(that[i]).hasClass("cb_active")){
                $(input).prop("checked","checked");
            }else{
                $(input).removeProp("checked");
            }
            console.log($(that[i]).children("input").prop("checked"));
        }

    }
    $(function(){

        $(".cbt").on('click',function(){
            console.log("点击了");

            //全部取消选中
            var divs = $(".cbt");
            for(var i=0; i<divs.length; i++){
                console.log("i= "+i + " this.i="+$(this).data('i'));
                if($(this).data('i') != $(divs[i]).data('i')){
                    $(divs[i]).children("input").removeProp("checked");
                    $(divs[i]).removeClass("cb_active");
                }
            }



            var input = $(this).children("input");
//            console.log(input);
            if($(this).hasClass("cb_active")){
                $(this).removeClass("cb_active");
            }else{
                $(this).addClass("cb_active");
            }
            check($(".cbt"));

            //post数据
            $.post(
                    '{:U("Address/update")}',
                    'id='+$(this).data("id")+"&default="+$(input).prop("checked"),
                    function(res){
                        console.log(res);
                    }
            );
        });


    });
</script>
<a href="{:U('Address/edit')}" class="address-btn" style="background:#e9a348">+ 添加新地址</a>
</body>
</html>
